package com.jml.callback;

import com.jml.service.RegisterService;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextClosedEvent;

/**
 * debug关闭的时候，会调用这个方法，非正常手段停止服务是不会走这个回调的。
 */
public class CloseCallbackImpl implements ApplicationListener<ContextClosedEvent> {

    private static final Log log = LogFactory.getLog(CloseCallbackImpl.class);

    @Autowired
    private RegisterService registerService;

    @Override
    public void onApplicationEvent(ContextClosedEvent contextClosedEvent) {
        log.info("服务停止了......");
        // 向服务注册中心 发送请求 移除该服务对应的ip和端口号码
        registerService.remove();
    }
}
